// components/coupon-wrapper/coupon-wrapper.js
Component({
  /**
   * 组件的属性列表
   */
  properties: {
    couponData: {
      type: Object,
      value: null
    },
    toggle: {
      type: Boolean,
      value: false,
      observer(v) {
        if (v) {
          this._open();
        } else {
          this._close();
        }
      }
    }
  },

  /**
   * 组件的初始数据
   */
  data: {
    show: false,
    selGoodsCoupons: [],
    animateData: {}
  },
  /**
   * 组件的方法列表
   */
  methods: {
    // 选择店铺券或无敌券
    selCoupon(e) {
      const index = e.currentTarget.dataset['index'] * 1;
      this.triggerEvent('selcoupon', {
        index
      });
    },

    // 单品抵扣券点击确定选择红包
    confirm() {
      this.triggerEvent('confirm');
    },

    _open() {
      const animate = wx.createAnimation({
        duration: 300,
        timingFunction: "ease",
        delay: 0
      })
      animate.translate3d(0, 417, 0).step();
      this.setData({
        show: true,
        animateData: animate.export()
      })
      setTimeout(() => {
        animate.translate3d(0, 0, 0).step();
        this.setData({
          animateData: animate.export()
        })
      }, 50)
    },

    _close() {
      const animate = wx.createAnimation({
        duration: 300,
        timingFunction: "ease",
        delay: 0
      })
      animate.translate3d(0, 417, 0).step();
      this.setData({
        animateData: animate.export()
      })
      setTimeout(() => {
        animate.translate3d(0, 417, 0).step();
        this.setData({
          animateData: animate.export(),
          show: false
        })
      }, 300)
    },

    close() {
      this.triggerEvent('close');
    },

    // 不使用优惠券
    noUsed() {
      this.triggerEvent('noused');
    }
  }
})